Skip to content

Conversation

@simonswine
Copy link
Contributor

@simonswine simonswine commented Nov 11, 2025

This PR adds support for .pyroscope.yaml configuration files for custom source code mappings and adds logic to use those mappings to find Go and Java code

  • Added .pyroscope.yaml configuration support for custom source code location mappings
  • Supports both local paths and GitHub repository mappings for Go and Java
  • Implements prefix-based matching with longest-prefix-wins strategy
  • Enhanced Go standard library resolution with version detection and configurable source
  • Added function_name parameter to file lookups, so java profiles (that don't contain file paths), can be looked up.
  • Improved error tracing with OpenTracing tags in GitHub client

Configuration Example (also in the PR):

This will map a special path prefix called $GOROOT to a particular go version. This signals to the backend the go version used to compile this should be kept update to date with the version of Pyroscope used to build.

  source_code:
    mappings:
      - path:
          - prefix: $GOROOT/src
        language: go
        source:
          github:
            owner: golang
            repo: go
            ref: go1.24.8
            path: src

@simonswine simonswine changed the title 20251111 experiment pyroscope yaml WIP: Experiment with .pyroscope.yaml Nov 11, 2025
@simonswine simonswine force-pushed the 20251111_experiment-pyroscope-yaml branch from 1a8e75f to fa7f045 Compare November 13, 2025 11:57
type: string
title: rootPath
description: the root path where the project lives inside the repository
functionName:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like currently logic is: use localPath if go, use functionName if java. May lead to confusion down the road if we start seeing java profiles with the file paths properly set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I guess the profiling data you send needs to match with the .pyroscope.yaml you set. I do think this makes sense and is both in customer control.

@simonswine simonswine force-pushed the 20251111_experiment-pyroscope-yaml branch from d5ab32d to 85d78f1 Compare November 14, 2025 17:22
@simonswine simonswine force-pushed the 20251111_experiment-pyroscope-yaml branch from e34c558 to 7d5ab4e Compare November 21, 2025 09:45
@simonswine simonswine changed the title WIP: Experiment with .pyroscope.yaml feat: Add .pyroscope.yaml with source code mapping support Nov 21, 2025
@simonswine simonswine marked this pull request as ready for review November 21, 2025 11:43
@simonswine simonswine requested review from a team, bryanhuhta and marcsanmi as code owners November 21, 2025 11:43
Copy link
Contributor

@bryanhuhta bryanhuhta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts for the future, but I like where this is at right now.

Copy link
Contributor

@jake-kramer jake-kramer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

}

// Validate checks if a source configuration is valid
func (m *Source) Validate() error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be helpful error message to surface if the supplied source is not supported (i.e. not github or local)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fully sure, if I am understanding this comment: There are two parts:

Not surfacing the error: I agree nothing surfaces this right now to a user, I think we will need first CLI support like profilescli pyroscope-yaml validate, but it should also be possible to surface them in Drilldown, when function details is used.

"if the supplied source is not supported (i.e. not github or local)": This will trigger the error in Line 136. Not too sure what else we could do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the "supplied source is not supported" I meant specifically this scenario:

mappings:
  - function_name:
    - prefix: org/example/rideshare
  language: java
  source:
     local:
       path: src
  - function_name:
    - prefix: org/example/foo
  language: java
  source:
     gitlab:
       path: src

will return the error "no source type supplied, you need to supply exactly one source type" which does not let the user know that gitlab is an unsupported source

return
}
sp.SetTag("config.url", file.URL)
sp.SetTag("config", file.Content)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this too large to tag in span?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not aware of any particular limits, infact this might be the only way for us to see those files, as we don't really have access to them if they are in a private repo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this max_attribute_bytes config which defaults to 2048 is related?

sp.SetTag("config.url", file.URL)
sp.SetTag("config", file.Content)

cfg, err := config.ParsePyroscopeConfig([]byte(file.Content))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I still think it would be useful to load up this config when the frontend loads up and WARN any errors just as a useful sanity check. OK to instead rely on config tooling I'm working on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this is possible, we need an end user to supply us an encrypted token and the owner/repo/root-path information before we can fetch a config.

// fetchRepoFile fetches the file content from the configured repository.
func (arg FileFinder) fetchRepoFile(ctx context.Context, path, ref string) (*vcsv1.GetFileResponse, error) {
if arg.rootPath != "" {
path = filepath.Join(arg.rootPath, path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: There's sort of a rough edge here where this root path is defined in the UI at repo level and then the mapping config can contain local paths that are function-level root paths. I can see as a user being confused playing with these two configs.

Maybe at some point a helper tooltip in the UI can clarify how these configs interact.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree, in order to make the UX workable, we need to show the parsed config in context to what else is configured. I don't think though this will be a good investment of time just yet.

At least of the paths in .pyroscope.yaml are relative to that file, and the only location we are reading .pyroscope.yaml from is the "rootPath".

@simonswine simonswine enabled auto-merge (squash) November 24, 2025 14:03
@simonswine simonswine merged commit 8d588a4 into main Nov 24, 2025
21 checks passed
@simonswine simonswine deleted the 20251111_experiment-pyroscope-yaml branch November 24, 2025 14:17
simonswine added a commit that referenced this pull request Nov 24, 2025
Also update the script for `.pyroscope.yaml` (was missed in #4606)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants